package com.community.process._1010.dao.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.community.process._1010.common.base.BaseEntity;
import com.community.process._1010.common.utils.SystemAmountUtil;
import com.community.process._1010.domains.ProcessFoodItemDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 到餐加工成品菜
 *
 * @author Zbs
 * @since 2024-09-05
 */
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@TableName("yg_process_food_item")
@Schema(description = "到餐加工成品菜")
public class ProcessFoodItem extends BaseEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    @Schema(description = "菜品名称")
    private String name;

    @Schema(description = "描述")
    private String description;

    @Schema(description = "菜品图片")
    private String image;

    @Schema(description = "分类ID")
    private Long categoryId;

    @Schema(description = "单位")
    private String units;

    @Schema(description = "重量")
    private Integer weight;

    @Schema(description = "成品菜价格 单位：分")
    private Long price;

    @Schema(description = "上下架 1 上架 0 下架")
    private Integer up;

    public ProcessFoodItem(ProcessFoodItemDTO.FoodItemAdd dto) {
        this.up = 1;
        initParams(dto);
    }

    public ProcessFoodItem(ProcessFoodItemDTO.FoodItemUpdate dto) {
        this.setId(dto.getId());
        this.up = dto.getUp();
        initParams(dto);
    }

    private void initParams(ProcessFoodItemDTO.FoodItemBase dto) {
        this.name = dto.getName();
        this.description = dto.getDescription();
        this.image = dto.getImage();
        this.categoryId = dto.getCategoryId();
        this.price = SystemAmountUtil.yuanToPenny(dto.getPrice());
        this.units = dto.getUnits();
        this.weight = dto.getWeight();
    }
}
